package main

import (
	"log"
	"net/http"

	"gitee.com/linker-group/lsas/app"
)

func main() {
	g := app.Global{}
	//设置配置文件
	g.ConfigFile = "config/config.ini"
	g.GlobalConfig = g.Config.GlobalConfig() //获取配置文件

	//静态文件定义
	fs := http.FileServer(http.Dir("statics"))
	http.Handle("/statics/", http.StripPrefix("/statics", fs))

	//路由
	http.HandleFunc("/login", g.Handler(g.Login))   //登录页面
	http.HandleFunc("/logout", g.Handler(g.Logout)) //登出
	http.HandleFunc("/error", g.Handler(g.Error))   //错误页面

	http.HandleFunc("/", g.AuthHandler(g.Index)) //首页

	//菜单管理菜单
	http.HandleFunc("/sys/menu", g.AuthHandler(g.SysMenu))        //菜单管理首页
	http.HandleFunc("/sys/menu_add", g.AuthHandler(g.SysMenuAdd)) //添加菜单
	http.HandleFunc("/sys/menu_del", g.AuthHandler(g.SysMenuDel)) //删除菜单

	//用户管理菜单
	http.HandleFunc("/sys/user", g.AuthHandler(g.SysUser))  //用户管理首页
	http.HandleFunc("/sys/user_add", g.AuthHandler(g.SysUserAdd))  //添加用户
	http.HandleFunc("/sys/user_del", g.AuthHandler(g.SysUserDel))  //删除用户
	http.HandleFunc("/sys/user_edit", g.AuthHandler(g.SysUserEDit))  //用户编辑


	//角色管理菜单
	http.HandleFunc("/sys/role", g.AuthHandler(g.SysRole))  //角色管理首页
	http.HandleFunc("/sys/role_add", g.AuthHandler(g.SysRoleAdd))  //添加角色
	http.HandleFunc("/sys/role_del", g.AuthHandler(g.SysRoleDel))  //删除角色

	//权限管理菜单
	http.HandleFunc("/sys/perms", g.AuthHandler(g.SysPerms))  //权限管理
	http.HandleFunc("/sys/perms_add", g.AuthHandler(g.SysPermsAdd))  //添加权限
	http.HandleFunc("/sys/perms_del", g.AuthHandler(g.SysPermsDel))  //添加权限

    //vpn管理菜单
	http.HandleFunc("/ldap/user", g.AuthHandler(g.LdapUser))  //ldap用户
	http.HandleFunc("/ldap/group", g.AuthHandler(g.LdapGroup))  //ldap用户组
	http.HandleFunc("/ldap/user_add", g.AuthHandler(g.LdapUserAdd))  //ldap用户添加
	http.HandleFunc("/ldap/group_add", g.AuthHandler(g.LdapGroupAdd))  //ldap用户添加
	http.HandleFunc("/ldap/user_del", g.AuthHandler(g.LdapUserDel))  //ldap用户删除
	http.HandleFunc("/ldap/group_del", g.AuthHandler(g.LdapGroupDel))  //ldap分组删除
	http.HandleFunc("/ldap/user_edit", g.AuthHandler(g.LdapUserEdit))  //ldap用户编辑
	http.HandleFunc("/ldap/group_edit", g.AuthHandler(g.LdapGroupEdit))  //ldap用户组编辑
	http.HandleFunc("/ldap/resepasswd", g.AuthHandler(g.ResePasswd))  //ldap用户重置密码
	http.HandleFunc("/ldap/sshkey_edit", g.AuthHandler(g.LdapUserSshKeyEdit))  //ldap用户sshkey管理
	http.HandleFunc("/ldap/user_host", g.AuthHandler(g.LdapUserHost))  //ldap用户主机管理
	http.HandleFunc("/ldap/user_vpn", g.AuthHandler(g.LdapUserVpn))  //ldap用户VPN管理

	//VPN列表管理菜单
	http.HandleFunc("/sys/vpn_list", g.AuthHandler(g.SysVpnList))  //VPN列表信息管理
	http.HandleFunc("/sys/vpn_list_add", g.AuthHandler(g.SysVpnListAdd))  //VPN列表信息添加
	http.HandleFunc("/sys/vpn_list_edit", g.AuthHandler(g.SysVpnList))  //VPN列表信息编辑
	http.HandleFunc("/sys/vpn_list_del", g.AuthHandler(g.SysVpnListDel))  //VPN列表信息删除

	//应用配置管理
	http.HandleFunc("/config/project", g.AuthHandler(g.ListProject)) //显示项目列表
	http.HandleFunc("/config/list", g.AuthHandler(g.ListConfig))     //显示配置列表
	http.HandleFunc("/config/add", g.AuthHandler(g.AddConfig))       //添加配置项
	http.HandleFunc("/config/newver", g.AuthHandler(g.NewVersion))   //新建版本
	http.HandleFunc("/config/chver", g.AuthHandler(g.ChangeVersion)) //切换版本
	http.HandleFunc("/config/del", g.AuthHandler(g.DelConfig))       //删除配置
	http.HandleFunc("/config/edit", g.AuthHandler(g.EditConfig))     //修改配置
	http.HandleFunc("/config/token", g.AuthHandler(g.ListToken))     //项目token列表
	http.HandleFunc("/config/newtoken", g.AuthHandler(g.NewToken))   //生成新token

	//saltstack
	http.HandleFunc("/salt/hosts", g.AuthHandler(g.Hosts))   //主机列表
	http.HandleFunc("/salt/update_hosts", g.AuthHandler(g.Update_Hosts))  //更新saltstack主机列表

	//saltstack_template
	http.HandleFunc("/salt/template", g.AuthHandler(g.SaltTemplate))  //模板列表
	http.HandleFunc("/salt/template_del", g.AuthHandler(g.SaltTemplateDel))    //删除模板
	http.HandleFunc("/salt/template_add", g.AuthHandler(g.SaltTemplateAdd))    //添加模板
	http.HandleFunc("/salt/template_edit", g.AuthHandler(g.SaltTemplateEdit))  //更新模板

	//代码发布
	http.HandleFunc("/deploy/java", g.AuthHandler(g.Deploy))  //Java项目代码发布
	http.HandleFunc("/deploy/project", g.AuthHandler(g.DeployProjectManage))  //代码发布项目管理


	ADDR := g.GlobalConfig["bind"] + ":" + g.GlobalConfig["port"]
	log.Println("开始启动监听" + ADDR)
	start_log := http.ListenAndServe(ADDR, nil)
	log.Println(start_log)

}
